﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using MSAst = Microsoft.Scripting.Ast;
using Microsoft.Scripting.Actions;
using Microsoft.Scripting.Shell;
using Microsoft.Scripting.Runtime;

using Gamadus.Engine.Compiler.Runtime;

namespace Gamadus.Engine.Compiler {
    public class GmlLanguageContext : LanguageContext {
        public GmlLanguageContext(ScriptDomainManager manager) : base(manager) { 
			Console.WriteLine("creating");
            Binder = new GmlBinder(new CodeContext(new Scope(this), this));
        }

        public override MSAst.LambdaExpression ParseSourceCode(CompilerContext context) {
            switch (context.SourceUnit.Kind) {
                case SourceCodeKind.InteractiveCode:
					throw new NotImplementedException();

                default:
                    context.SourceUnit.CodeProperties = SourceCodeProperties.None;
                    return Compiler.Compile(context.SourceUnit.GetCode());
            }
        }

        public override string DisplayName {
            get { return "ToyScript"; }
        }

        public override ServiceType GetService<ServiceType>(params object[] args) {
            if (typeof(ServiceType) == typeof(OptionsParser)) {
                return (ServiceType)(object)new DefaultOptionsParser(this);
            } else if (typeof(ServiceType) == typeof(CommandLine)) {
                return (ServiceType)(object)new GmlCommandLine();
            }

            return base.GetService<ServiceType>(args);
        }
    }
}
